package com.feilx.changgou.goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import com.changgou.bean.PageVo;
import com.changgou.bean.QueryCondition;
import com.changgou.bean.Resp;
import com.changgou.entity.Sku;
import com.changgou.pojo.SkuInfo;
import com.changgou.pojo.TbSkuEntity;
import com.feilx.changgou.goods.service.TbSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;





/**
 * 商品表
 *
 * @author feilx
 * @email 852371260@qq.com
 * @date 2020-08-01 14:05:04
 */
@Api(tags = "商品表 管理")
@RestController
@RequestMapping("/sku")
public class TbSkuController {
    @Autowired
    private TbSkuService tbSkuService;

    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @GetMapping("/list")
    public Resp<PageVo> list(QueryCondition queryCondition) {
        PageVo page = tbSkuService.queryPage(queryCondition);
        return Resp.ok(page);
    }


    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @GetMapping("/info/{id}")
    public Resp<TbSkuEntity> info(@PathVariable("id") Long id){
		TbSkuEntity tbSku = tbSkuService.getById(id);

        return Resp.ok(tbSku);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")

    public Resp<Object> save(@RequestBody TbSkuEntity tbSku){
		tbSkuService.save(tbSku);

        return Resp.ok(null);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    public Resp<Object> update(@RequestBody TbSkuEntity tbSku){
		tbSkuService.updateById(tbSku);

        return Resp.ok(null);
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    public Resp<Object> delete(@RequestBody Long[] ids){
		tbSkuService.removeByIds(Arrays.asList(ids));

        return Resp.ok(null);
    }

    @ApiOperation("分页查询(排序)")
    @GetMapping("/getAll")
    public List<SkuInfo> getAll(@RequestParam Map map) {
        List<SkuInfo> page = tbSkuService.getAll(map);
        return page;
    }


}
